package org.rcloud.io.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.CollectMapper;
import org.rcloud.io.model.Collect;
import org.rcloud.io.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/2/26.
 */
@Service(value = "CollectService")
public class CollectServiceImpl implements CollectService {

    @Autowired
    private CollectMapper collectMapper;

    @Override
    public ResultVo deleteByPrimaryKey(Collect id) {

        if (id.equals("") || id == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int delete = collectMapper.deleteByPrimaryKey(id);
                return ResultVo.setOK(delete);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo insert(Collect record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = collectMapper.insert(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo insertSelective(Collect record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = collectMapper.insertSelective(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo selectByPrimaryKey(Collect id) {

        if (id.equals("") || id == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                Collect collect = collectMapper.selectByPrimaryKey(id);
                return ResultVo.setOK(collect);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo updateByPrimaryKeySelective(Collect record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = collectMapper.updateByPrimaryKeySelective(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo updateByPrimaryKey(Collect record) {

        if (record.equals("") || record == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = collectMapper.updateByPrimaryKey(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public PageInfo<Collect> selectByOther(int pageNum, int pageSize, Map map) {
        PageHelper.startPage(pageNum,pageSize,true);
        List<Collect> collectList = collectMapper.selectByOther(map);
        PageInfo<Collect> pageInfo = new PageInfo<>(collectList);
        return pageInfo;
    }

    @Override
    public PageVo<Collect> selectByCollectEid(Collect userid) {

        if (userid.equals("") || userid == null){
            return PageVo.setError("传入数据为空");
        } else {
            try {
                List<Collect> list = collectMapper.selectByCollectEid(userid);
                return PageVo.setOk(list);
            } catch (Exception e) {
                e.printStackTrace();
                return PageVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public PageVo<Collect> selectByLike(Collect eid) {


        if (eid.equals("") || eid == null){
            return PageVo.setError("传入数据为空");
        } else {
            try {
                List<Collect> list = collectMapper.selectByLike(eid);
                return PageVo.setOk(list);
            } catch (Exception e) {
                e.printStackTrace();
                return PageVo.setError(e.getMessage());
            }
        }

    }


}
